﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bigger.Base;
using Bigger.Framework;

namespace CJAtech.BBS.Web.Controllers
{
    public partial class SSOBBSController
    {
        public ActionResult AnnounceList()
        {
            return BBSView();
        }

        public ActionResult Announce(int? id)
        {
            return Article(id);
        }

        /// <summary>
        /// 奔驰公共列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public ActionResult GetAnnounceListByBenz(int? pageIndex = 1, int? pageSize = 10)
        {
            if (!IsUserBelongSmart())
            {
                return Json(new InvokeResult { ResultCode = "NotAllowed", ResultMessage = "对不起，你没有权限访问" }, JsonRequestBehavior.AllowGet);
            }
            return ArticleListJson(3, pageIndex, pageSize);
        }

        /// <summary>
        /// 奔驰公告详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult GetAnnounceByBenz(int? id)
        {
            if (!IsUserBelongSmart())
            {
                return Json(new InvokeResult { ResultCode = "NotAllowed", ResultMessage = "对不起，你没有权限访问" }, JsonRequestBehavior.AllowGet);
            }
            return GetArticle(id);
        }

        /// <summary>
        /// 奔驰用户是否属于Smart用户
        /// </summary>
        /// <returns></returns>
        [NonAction]
        public bool IsUserBelongSmart()
        {
            DbContext objDbContext = new DbContext("CJAtech.Hrms.ConnectionString");
            object obj = objDbContext.ExecuteScalar("select * from T_USERINFO_SMART where id=@id", new { id = this.CurrentUserInfo.UserId });
            return obj != null;
        }
    }
}
